﻿//-----------------------------------------------------------------
//
// @(#)$Id: EbayFeeGenerateDocumentsDetail.aspx.cs,v 1.0 2013/12/13 17:15:57 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:15:57 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_BasTableAdapters;

public partial class UI_Bas_EbayFeeGenerateDocumentsDetail : System.Web.UI.Page
{
    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {          
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        txtCreateDate.Value = DateTime.Now.ToString();
                        break;
                    case "U":
                        {
                            this.txtId.Attributes["readonly"] = "readonly";
                            int Id = int.Parse(Request.QueryString["id"]);
                            T_CreateDocumentsTypeTableAdapter ebayAdapter = new T_CreateDocumentsTypeTableAdapter();
                            DataTable dt = ebayAdapter.GetDataById(Id);
                            DataRow r = dt.Rows[0];
                            txtId.Value = r["Id"].ToString();
                            txtDocumentsTypeId.Value = r["DocumentsTypeId"].ToString();
                            txtFeeType.Value = r["FeeType"].ToString();
                            txtCreateDate.Value = r["CreateDate"].ToString();
                        }
                        break;
                }
            }
        }
    }
   
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_CreateDocumentsTypeTableAdapter ebayAdapter = new T_CreateDocumentsTypeTableAdapter();
                        int flag = (int)ebayAdapter.IsExists(int.Parse(txtId.Value));
                        if (flag == 0)
                        {
                            int val = ebayAdapter.Insert(
                                    int.Parse(txtId.Value),
                                    txtFeeType.Value,
                                    txtDocumentsTypeId.Value,
                                    Convert.ToDateTime(txtCreateDate.Value)
                                     );
                            if (val > 0)
                            {
                                Response.Write("<script>alert('添加成功!');window.location.href='EbayFeeGenerateDocuments.aspx'</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('编号已经存在!..');</script>");
                        }
                    }
                    break;
                case "U":
                    {                    
                        int id = int.Parse(Request.QueryString["id"]);
                        T_CreateDocumentsTypeTableAdapter adapter = new T_CreateDocumentsTypeTableAdapter();
                        int val = adapter.Update(
                                txtFeeType.Value,
                                txtDocumentsTypeId.Value,
                                Convert .ToDateTime (txtCreateDate .Value ),
                                int.Parse(txtId.Value)
                                );
                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='EbayFeeGenerateDocuments.aspx'</script>");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}